package com.xxx.yuedong.mine.controller;

import cn.hutool.json.JSONUtil;
import com.xxx.yuedong.common.R;
import com.xxx.yuedong.mine.controller.form.*;
import com.xxx.yuedong.mine.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;

@RequestMapping("/role")
@Api(tags = "角色相关接口")
@Slf4j
@RestController
public class RoleController {
    @Autowired
    private RoleService roleService;

    @PostMapping("/list")
    @ApiOperation("角色列表")
    public R list(@Valid @RequestBody SearchRoleListForm form){
        HashMap param = JSONUtil.parse(form).toBean(HashMap.class);
        return roleService.list(param);
    }

    @PostMapping("/insert")
    @ApiOperation("新增角色")
    public R insert(@Valid @RequestBody InsertRoleForm form){
        HashMap param = JSONUtil.parse(form).toBean(HashMap.class);
        return roleService.insert(param);
    }

    @PostMapping("/update")
    @ApiOperation("更新角色")
    public R update(@Valid @RequestBody UpdateRoleForm form){
        HashMap param = JSONUtil.parse(form).toBean(HashMap.class);
        return roleService.update(param);
    }

    @PostMapping("/searchRoleInfo")
    @ApiOperation("查询角色信息")
    public R searchRoleInfo(@Valid @RequestBody SearchRoleInfoForm form){
        return roleService.searchRoleInfo(form.getId());
    }

    @PostMapping("/delete")
    @ApiOperation("删除角色信息")
    public R delete(@Valid @RequestBody DeleteRoleByIdsForm form){
        return roleService.delete(form.getIds());
    }

    @PostMapping("/getRoleList")
    @ApiOperation("角色列表")
    public R getRoleList(){
        return roleService.getRoleList();
    }
}
